/*  This file is part of the comicconquer project
    Copyright (C) 2010 Reach <reach334@gmail.com>

    ComicConquer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public 
    License along with this software.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "CoTabPage.h"

CoTabPage::CoTabPage(QWidget* parent)
: QWidget(parent),
m_layout(this)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    m_curFocusWidget = 0;

    Out_Log(__FUNCTION__, COCLASSNAME);
}

CoGroupBox* CoTabPage::addGroupBox(const QString& name, const QString& text)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    CoGroupBox* groupBox = new CoGroupBox(text, this);
    m_layout.addWidget(groupBox);
    m_widgetMap[name] = static_cast<QWidget*>(groupBox);
    m_widgetVec.append(static_cast<QWidget*>(groupBox));

    Out_Log(__FUNCTION__, COCLASSNAME);
    return groupBox;
}

CoGroupBox* CoTabPage::getGroupBox(const QString& name)
{
    return static_cast<CoGroupBox*>(m_widgetMap[name]);
}

QWidget* CoTabPage::addWidget(const QString& name, QWidget* widget)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    m_layout.addWidget(widget);
    m_widgetMap[name] = static_cast<QWidget*>(widget);
    m_widgetVec.append(static_cast<QWidget*>(widget));

    Out_Log(__FUNCTION__, COCLASSNAME);
    return widget;

}

QWidget* CoTabPage::getWidget(const QString& name)
{
    return m_widgetMap[name];
}

QWidget* CoTabPage::getWidget(int id)
{
    return m_widgetVec[id];
}

CoCheckButton* CoTabPage::getCheckButton(const QString& groupBoxName, const QString& widgetName)
{
    return getGroupBox(groupBoxName)->getCheckButton(widgetName);
}

CoRadioButtonGroup* CoTabPage::getRadioButtonGroup(const QString& groupBoxName, const QString& widgetName)
{
    return getGroupBox(groupBoxName)->getRadioButtonGroup(widgetName);
}

CoNumberEditor* CoTabPage::getNumberEditor(const QString& groupBoxName, const QString& widgetName)
{
    return getGroupBox(groupBoxName)->getNumberEditor(widgetName);
}

void CoTabPage::addStretch(int stretch)
{
    m_layout.addStretch(stretch);
}

void CoTabPage::clear()
{
    for (int i = 0; i < m_widgetVec.count(); i++)
    {
        m_widgetVec[i]->close();
    }

    m_widgetMap.clear();
    m_widgetVec.clear();
    m_curFocusWidget = 0;
}

